import utils from '@/common/utils'
export default {
	data() {
		return {
			repairTypeList: [{
				text: "上门维修",
				value: 1
			}, {
				text: "用户送修",
				value: 2
			}, {
				text: "网点拉修",
				value: 3
			}, {
				text: "用户寄修",
				value: 4
			}],
			repairTypeIndex: 0,
			woProducts: [],
			woTransInfo: {},
			woCacheData: {},
		}
	},
	methods: {
		async GetOrderDataImg() {
			let UsePhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId

			let result = await this.workorderlistervice.CacheOrderInfoAsync(UsePhone, 2,
				this.orderDetailId, "",
				token);
			if (result && result.RetBool) {
				let data = JSON.parse(result.RetObject);
				let orderDetailData = JSON.parse(data.NewWoData);
				return orderDetailData.WoItemPicture;
			}
		},
		async GetOrderData() {
			let uPhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId
			let result = await this.workorderlistervice.CacheOrderInfoAsync(uPhone, 2, this.orderDetailId, "",
				token);

			if (result && result.RetBool) {
				let data = JSON.parse(result.RetObject);
				this.orderDetailData = JSON.parse(data.NewWoData);
				//let CacheData = data.CacheWoData?JSON.parse(data.CacheWoData):null;
				console.log("orderDetailData", this.orderDetailData);
			} else {
				uni.showToast({
					title: "获取工单信息失败" + result.RetMsg,
					icon: "none"
				});
			}
			uni.hideLoading();
		},
		firstChar(str) {
			if (str)
				return str.charAt(0);
			else
				return ""
		},
		//确认产品
		async AffirmProduct(index) {
			let prodect = this.orderDetailData.WoProuduct[index];
			console.log(prodect);
			if (!prodect.Barcode) {
				uni.showToast({
					title: "物流码不能为空",
					icon: "none"
				});
				return;
			}
			if (!prodect.PurchaseDate) {
				uni.showToast({
					title: "保修开始时间不能为空",
					icon: "none"
				});
				return;
			}
			let result = await this.workordercompleteservice.ConfirmProductAsync(this.UserInfo.mobile, this.orderDetailData.WoFinishType,
				prodect.Barcode, prodect.ProuctId, prodect.WoObjectId, this.orderDetailId, prodect.PurchaseDate, this.UserInfo.RetId
			);
			console.log(result);
			if (result) {
				if (result.RetBool) {
					uni.showToast({
						title: "产品确认成功",
						icon: "none"
					});
					prodect.IsProductConfirmed = true;
					console.log(this.orderDetailData);

				} else {
					uni.showToast({
						title: `产品确认失败:${result.RetMsg}`,
						icon: "none"
					});
				}
			} else {
				uni.showToast({
					title: "产品确认失败!",
					icon: "none"
				});
			}
			uni.hideLoading();
		},

		getImageBase64(itempic) {
			let srcbase64 = `data:image/${itempic.FileType.replace('.','')};base64,${itempic.ImageContent}`;
			return srcbase64;
		},

		//验证物理码
		async BarcodeValidCheckAsync(index, Barcode) {
			let userPhone = this.UserInfo.mobile
			let token = this.UserInfo.RetId
			let result = await this.workordercompleteservice
				.BarcodeValidCheckAsync(userPhone, Barcode, token);
			if (result && result.RetBool) {
				let data = JSON.parse(result.RetObject);
				return data;
			} else {
				console.log(result.RetMsg);
				throw result.RetMsg;
			}
		},

		//验证后刷新产品信息
		RefreshProduct(data, index, Barcode) {
			let productItem = this.orderDetailData.WoProuduct[index];
			if (data && data.IsValid) {
				productItem.Barcode = Barcode;
				productItem.IsSerialValid = "有效";
				if (data.ItemIdGUID) {
					productItem.ProductNum = data.ProductName;
					productItem.ProductName = data.ProductNum;
					productItem.ProuctId = data.ItemIdGUID;
					productItem.ProdTypeGroup = data.ProductTypeGroupName;
					productItem.WaterAnalysisFieldRequired = data.WaterAnalysisFieldRequired;
					productItem.ProductImage = (data.ProductImage != null && data.ProductImage != 'null' && data.ProductImage != '') ?
						"data:image/jpeg;base64," + data.ProductImage : "";
					productItem.proFaultyGroup = data.FaultyGroup;
					productItem.proFaultyGroupName = data.FaultyGroupName;
					productItem.IsRequired = data.IsRequired;
					productItem.isCheckBarcode = true;
					productItem.isDisplayProdInputField = true;
					uni.hideLoading();
				} else {
					productItem.isCheckBarcode = true;
					productItem.isDisplayProdInputField = false;
					uni.hideLoading();
					uni.showToast({
						title: "物流码有效，但没有匹配到关联产品，请从产品选择",
						icon: "none",
						duration: 2000
					});
				}
			} else {
				productItem.Barcode = "";
				uni.hideLoading();
				uni.showToast({
					title: "物流码无效，请重新输入",
					icon: "none",
					duration: 2000
				});
			}
		},

		//解析数据
		initData(WoData) {
			let tempWoFinishedProList = [];
			//赋值工单头数据
			this.AssignOrderInfo(WoData);
			if (WoData.ShelfLife == 1)
				this.isShowActualReceiptAmountField = true;
			for (let index in WoData.WoProuduct) {
				//物流码
				let itemPro = WoData.WoProuduct[index];
				console.log("缓存信息");
				console.log(itemPro);
				let result = this.IsLogisticsCodeAndProductFill(itemPro, WoData);
				let fp_ProInfoItem = {
					'WoObjectId': itemPro.WoObjectId,
					'proHisNum': itemPro.ProductNum,
					'proHisId': itemPro.ProuctId,
					'proHisTypeGroup': itemPro.ProdTypeGroup,
					'proHisName': itemPro.ProductName,
					'proHisPurchaseSourceName': itemPro.PurchaseSourceText,
					'proHisPurchaseStoreName': itemPro.PurchaseChanel,
					'proHisBarcode': itemPro.Barcode,
					'proHisIsValidBarcode': itemPro.IsSerialValid,
					'proHisPurchaseDate': itemPro.PurchaseDate,
					'ProductNum': itemPro.ProductNum,
					'ProuctId': itemPro.ProuctId,
					'ProdTypeGroup': itemPro.ProdTypeGroup,
					'ProductName': itemPro.ProductName,
					'PurchaseSourceText': itemPro.PurchaseSourceText,
					'InstallLocation': itemPro.InstallLocation,
					'PurchaseChanel': itemPro.PurchaseChanel,
					'PurchaseDate': itemPro.PurchaseDate,
					'Barcode': itemPro.Barcode,
					'IsSerialValid': itemPro.IsSerialValid,
					'ProductImage': (itemPro.ProductImage != null && itemPro.ProductImage != 'null' && itemPro.ProductImage != '') ?
						"data:image/jpeg;base64," + itemPro.ProductImage : "",
					'IsProductConfirmed': itemPro.IsProductConfirmed,
					'proOriBarcode': itemPro.Barcode,
					'isBarcodeRequired': result.isBarcodeRequired,
					'isCheckBarcode': result.isCheckBarcode,
					'isShowBarcodeCheckBtn': false,
					'isDisplayProdInputField': result.isDisplayProdInputField,
					'isDisplayNewProdInputField': true,
					'isShowNewBarcodeCheckBtn': false,
					'proNewInstallPosition': null,
					'proIsNewBarcodeRequired': result.isBarcodeRequired,
					'proIsCheckNewBarcode': false,
					'proNewBarcode': null,
					'proNewProductID': null,
					'proNewProductName': null,
					'proNewProductNum': null,
					'proOriNewBarcode': null,
					'proCustProdID': itemPro.CustProductId,
					'WaterAnalysisFieldRequired': itemPro.WaterAnalysisFieldRequired,
					'OriWaterAnalysisId': itemPro.OriWaterAnalysisId,
					'ProductSeriesId': itemPro.ProductSeriesId,
					'ProductSeriesName': itemPro.ProductSeriesName,
					'OriTDS': itemPro.OriTDS,
					'OriTemperature': itemPro.OriTemperature,
					'OriHardness': itemPro.OriHardness,
					'OriChlorine': itemPro.OriChlorine,
					'NewTDS': itemPro.NewTDS,
					'NewHardness': itemPro.NewHardness,
					'NewChlorine': itemPro.NewChlorine,
					'IsRequired': itemPro.IsRequired,
					'IsWaterAnalysis': false,
					'isShowWaterAnalysisAddBtn': itemPro.IsShowWaterAnalysisAddBtn,
					'WarrantyEndDate': itemPro.WarrantyEndDate,
					'WarrantyStartDate': itemPro.WarrantyStartDate,
					'SuitProductName': itemPro.SuitProductName,
					'SuitProductDescription': itemPro.SuitProductDescription,
					'OnlyChangeEndDate': itemPro.OnlyChangeEndDate,
					'IsLogisticsCodeFill': itemPro.IsProductConfirmed,
					'IsProductFill': result.isDisplayProdInputField,
					//维修信息
					'Repairs': itemPro.Repairs,
				};
				tempWoFinishedProList.push(fp_ProInfoItem)
			}
			WoData.WoProuduct = tempWoFinishedProList;

		},

		IsLogisticsCodeAndProductFill(itemPro, woData) {
			//物流码是否可填
			let isBarcodeRequired = false;
			//产品是否可填
			let isDisplayProdInputField = true;
			//
			let isCheckBarcode = false;
			if (itemPro.IsProductConfirmed == false) {
				// ShelfLife【1：保外；2：保内；3：保外转保内】
				// InWarrantySerialCtrl；OutWarrantySerialCtrl【1：不验证；2：工单完工验证；3：产品确认验证】
				console.log("保内保外：", woData.ShelfLife);
				console.log("保内控制：", woData.InWarrantySerialCtrl);
				console.log("保外控制：", woData.OutWarrantySerialCtrl);
				if (woData.ShelfLife == 1 && woData.InWarrantySerialCtrl != 1) {
					isBarcodeRequired = true;
				} else if (woData.ShelfLife == 2 && woData.OutWarrantySerialCtrl != 1) {
					isBarcodeRequired = true;
				} else {
					isDisplayProdInputField = false;
				}
			} else {
				isCheckBarcode = true;
			}
			return {
				isBarcodeRequired: isBarcodeRequired,
				isDisplayProdInputField: isDisplayProdInputField,
				isCheckBarcode: isCheckBarcode
			};
		},

		//解析水质检测必填项
		ParseWaterAnalysisFieldRequired(strWaterAnalysisFieldRequired) {
			if (strWaterAnalysisFieldRequired != null && strWaterAnalysisFieldRequired != "") {
				let objFieldRequired = {};
				let listItem = strWaterAnalysisFieldRequired.split("|");
				for (let j = 0; j < listItem.length; j++) {
					let strItem = listItem[j];
					let field = strItem.split("=");
					if (field[0] == "OriTDS") {
						objFieldRequired.OriTDS = (field[1] == 1) ? true : false;
					} else if (field[0] == "OriTemperature") {
						objFieldRequired.OriTemperature = (field[1] == 1) ? true : false;
					} else if (field[0] == "OriHardness") {
						objFieldRequired.OriHardness = (field[1] == 1) ? true : false;
					} else if (field[0] == "OriChlorine") {
						objFieldRequired.OriChlorine = (field[1] == 1) ? true : false;
					} else if (field[0] == "NewTDS") {
						objFieldRequired.NewTDS = (field[1] == 1) ? true : false;
					} else if (field[0] == "NewHardness") {
						objFieldRequired.NewHardness = (field[1] == 1) ? true : false;
					} else if (field[0] == "NewChlorine") {
						objFieldRequired.NewChlorine = (field[1] == 1) ? true : false;
					}
				}
				return objFieldRequired;
			} else {
				return null;
			}
		},
		formatDate(data) {
			if (data) {
				debugger
				var format = data.replace(/-/g, '/')
				var timestamp=utils.formatDate(new Date(format),"yyyy/MM/dd");
				return timestamp;
				// return utils.formatDate(new Date(datestr), fmt);
			}
			return '';
		},

		//提交工单
		async SubmitOrder() {
			console.log("维修工单提交");
			uni.showLoading({
				title: "提交中..",
				mask: true,
			})
			//数据检测
			let IsAllValid = this.CheckDataBySubmitFinish();
			if (IsAllValid) {
				this.ConstructWoSubmitDataObject(); //构建完工对象
				let strCacheData = this.GetCacheOrderInfo(); //构建缓存对象
				console.log(this.woTransInfo, this.woProducts);
				let result = await this.workordercompleteservice.WOSubmitActionAsync(this.UserInfo.mobile, this.woTransInfo, this.woProducts,
					strCacheData, this.UserInfo.RetId);
				uni.hideLoading();
				console.log(result);
				if (result) {
					if (result.RetBool) {
						uni.showToast({
							title: "提交完工成功",
							icon: "none",
							duration: 3000
						});
						uni.switchTab({
							url: '../../workorder/index',
							success: () => {
								uni.$emit("ReLoadWorder");
							}
						});
					} else {
						uni.showToast({
							title: "提交完工失败:" + result.RetMsg,
							icon: "none",
							duration: 3000
						});
					}
				} else {
					uni.showToast({
						title: "提交完工失败",
						icon: "none",
						duration: 3000
					});
				}
			}
		},

		//完工数据检测
		CheckDataBySubmitFinish() {
			let toastduration = 3000
			//完工备注
			if (this.OrderRremark != "") {
				let IsContainSpecial = this.CheckSpecial(this.OrderRremark);
				if (IsContainSpecial) {
					uni.showToast({
						title: "完工备注不能包含如下特殊字符(%()\;:\'\",.\\/)",
						icon: "none",
						duration: toastduration
					});
					return false;
				}
			}
			//验证产品选择、物流码输入字段、购机日期、装机位置
			for (let index in this.orderDetailData.WoProuduct) {
				let ProductItem = this.orderDetailData.WoProuduct[index];
				let proIsConfirmed = ProductItem.IsProductConfirmed
				let proBarcode = ProductItem.Barcode;
				let proNum = ProductItem.ProductNum;
				let isBarcodeRequired = ProductItem.IsBarcodeRequired;
				let proInstallPosition = ProductItem.InstallLocation;
				let proPurchaseDate = ProductItem.PurchaseDate;
				if (!proIsConfirmed) {
					let proId = ProductItem.ProuctId;
					if (proId == null || proId == "") {
						uni.showToast({
							title: "产品字段不能为空值，请选择！",
							icon: "none",
							duration: 10000
						});
						return false;
					}
					if (proBarcode && proBarcode != "") {
						let isCheckBarcode = ProductItem.isCheckBarcode;
						if (isCheckBarcode != true) {
							uni.showToast({
								title: `产品：${proNum}输入的物流码未验证！`,
								icon: "none",
								duration: 10000
							});
							return false;
						}
					} else if (isBarcodeRequired == true && (proBarcode == null || proBarcode == "")) {
						uni.showToast({
							title: `产品：${proNum}物流码不能为空！`,
							icon: "none",
							duration: 10000
						});
						return false;
					}
				}
				if (proBarcode != null && proBarcode != "") {
					let isContainSpecial = this.CheckSpecial(proBarcode);
					if (isContainSpecial == true) {
						uni.showToast({
							title: '物流码不能包含如下特殊字符',
							icon: "none",
							duration: 10000
						});
						return false;
					}
				}
				if (proPurchaseDate == null || proPurchaseDate == "") {
					uni.showToast({
						title: `产品：${proNum}购机日期不能为空！`,
						icon: "none",
						duration: 10000
					});
					return false;
				}
				//检测维修行
				if (!ProductItem.Repairs || ProductItem.Repairs.length == 0) {
					uni.showToast({
						title: `产品：${proNum}请添加维修信息行！`,
						icon: "none",
						duration: toastduration
					});
					return false;
				}
				//水质检测字段检测
				if (ProductItem.IsRequired == true && ProductItem.IsWaterAnalysis == false) {
					uni.showToast({
						title: `产品：${proNum}未填写水质检测信息！`,
						icon: "none",
						duration: toastduration
					});
					return false;
				}
				if (ProductItem.IsRequired == true) {
					let strWaterAnalysisFieldRequired = ProductItem.WaterAnalysisFieldRequired;
					let objFieldRequired = this.ParseWaterAnalysisFieldRequired(strWaterAnalysisFieldRequired);
					if (objFieldRequired != null) {
						if (objFieldRequired.OriTDS == true && (ProductItem.OriTDS == null || ProductItem.OriTDS == "")) {
							uni.showToast({
								title: `产品：${proNum}水质检测项“原水TDS”为必填项，请填写后再提交完工！`,
								icon: "none",
								duration: toastduration
							});
							return false;
						}
						if (objFieldRequired.OriTemperature == true && (ProductItem.OriTemperature == null || ProductItem.OriTemperature ==
								"")) {
							uni.showToast({
								title: `产品：${proNum}水质检测项“原水水温”为必填项，请填写后再提交完工！`,
								icon: "none",
								duration: toastduration
							});
							return false;
						}
						if (objFieldRequired.OriHardness == true && (ProductItem.OriHardness == null || ProductItem.OriHardness == "")) {
							uni.showToast({
								title: `产品：${proNum}水质检测项“原水硬度”为必填项，请填写后再提交完工！`,
								icon: "none",
								duration: toastduration
							});
							return false;
						}
						if (objFieldRequired.OriChlorine == true && (ProductItem.OriChlorine == null || ProductItem.OriChlorine == "")) {
							uni.showToast({
								title: `产品：${proNum}水质检测项“原水余氯”为必填项，请填写后再提交完工！`,
								icon: "none",
								duration: toastduration
							});
							return false;
						}
						if (objFieldRequired.NewTDS == true && (ProductItem.NewTDS == null || ProductItem.NewTDS == "")) {
							uni.showToast({
								title: `产品：${proNum}水质检测项“纯水TDS”为必填项，请填写后再提交完工！`,
								icon: "none",
								duration: toastduration
							});
							return false;
						}
						if (objFieldRequired.NewHardness == true && (ProductItem.NewHardness == null || ProductItem.NewHardness == "")) {
							uni.showToast({
								title: `产品：${proNum}水质检测项“软化后硬度”为必填项，请填写后再提交完工！`,
								icon: "none",
								duration: toastduration
							});
							return false;
						}
						if (objFieldRequired.NewChlorine == true && (ProductItem.NewChlorine == null || ProductItem.NewChlorine == "")) {
							uni.showToast({
								title: `产品：${proNum}水质检测项“净化后余氯”为必填项，请填写后再提交完工！`,
								icon: "none",
								duration: toastduration
							});
							return false;
						}
					}
				}
			}
			// 验证实际收款总金额字段
			if (this.isShowActualReceiptAmountField == true) {
				let valAmount = this.ActualReceiptAmount;
				if (!valAmount) {
					uni.showToast({
						title: "实际收款总金额不能为空！",
						icon: "none"
					});
					return false;
				}
			}
			return true;
		},

		CheckSpecial: function(str) {
			var containSpecial = RegExp(/[(\%)(\()(\))(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)]+/);
			return (containSpecial.test(str));
		},

		//构造工单完工提交数据对象
		ConstructWoSubmitDataObject() {
			let sumbitOrderData = {};
			this.woTransInfo = {};
			this.woProducts = [];
			this.woTransInfo.ServiceOrder = this.orderDetailId;
			this.woTransInfo.Operator = ""; // 操作服务工程师
			this.woTransInfo.Type = 20; // 工单事务类型
			this.woTransInfo.FinishType = this.orderDetailData.WoFinishType; // 完工类型
			this.woTransInfo.Description = this.OrderRremark //备注
			this.woTransInfo.RepairType = this.repairTypeList[this.repairTypeIndex].value;
			this.woTransInfo.IsRepalced = false; //是否换机
			this.woTransInfo.ActualReceivedAmount = this.ActualReceiptAmount; //实际收款金额
			this.woTransInfo.CustomerRequiresMaintenanceDate = this.CustomerRequiresMaintenanceDate;
			for (let index in this.orderDetailData.WoProuduct) {
				let prodItem = this.orderDetailData.WoProuduct[index];
				//产品信息
				let product = {
					ServiceOrderObject: prodItem.WoObjectId, // 服务工单对象
					Barcode: prodItem.Barcode, // 物流码
					New_Barcode: "", //换机新物流码
					PurchaseDate: prodItem.PurchaseDate, // 购机日期
					Product: prodItem.ProuctId, // 产品
					Province: "", // 新省/市
					City: "", // 新市/区
					County: "", // 新区/县
					Street: "", // 新街道
					InstalledLocation: prodItem.InstallLocation, // 安装位置
					InstalledLocatuion_New: "", // 新安装位置
					SuitProductItems: "",
					Maintains: [],

				};
				//水质检测信息
				let waterAnalysis = {
					OriWaterAnalysisId: prodItem.OriWaterAnalysisId,
					OriTDS: prodItem.OriTDS,
					OriTemperature: prodItem.OriTemperature,
					OriHardness: prodItem.OriHardness,
					OriChlorine: prodItem.OriChlorine,
					NewTDS: prodItem.NewTDS,
					NewHardness: prodItem.NewHardness,
					NewChlorine: prodItem.NewChlorine,
					IsWaterAnalysis: prodItem.IsWaterAnalysis,
					ProductSeriesId: prodItem.ProductSeriesId,
					ProductSeriesName: prodItem.ProductSeriesName,
					IsRequired: prodItem.IsRequired
				};

				let RepairData = [];
				for (let repaisindex in prodItem.Repairs) {
					let Repairs = {
						FaultGroup: "",
						FaultClass: "",
						FaultExpression: "",
						FaultPosition: "",
						FaultReason: "",
						Solution: "",
						IsReplace: false,
						Warranty: 1,
						Assemblybom: "",
						EnsembleAccessoryStructure: "",
						FaultProduct: "",
						FaultProdName: "",
						ChangeParts: "",
						ChangePartName: "",
						RepairMarks: "",
						IsInWarrantyToOut: false,
						InWarrantyToOutReasonCode: "",
						IsOutWarrantyToIn: false,
						InWarrantyToOutReasonCode: "",
						WarrantyMarks: "",
					};
					let repaisitem = prodItem.Repairs[repaisindex];
					// 故障组ID
					if (repaisitem.faultyGroup)
						Repairs.FaultGroup = repaisitem.faultyGroup;
					while (repaisitem.confirmSelectFaultItem.hasOwnProperty('parentFaultItem')) {
						if (repaisitem.confirmSelectFaultItem.level == 1) {
							Repairs.FaultClass = repaisitem.confirmSelectFaultItem.RepairFaultId;
						}
						if (repaisitem.confirmSelectFaultItem.level == 2) {
							Repairs.FaultExpression = repaisitem.confirmSelectFaultItem.RepairFaultId;
						}
						if (repaisitem.confirmSelectFaultItem.level == 3) {
							Repairs.FaultPosition = repaisitem.confirmSelectFaultItem.RepairFaultId;
						}
						if (repaisitem.confirmSelectFaultItem.level == 4) {
							Repairs.FaultReason = repaisitem.confirmSelectFaultItem.RepairFaultId;
						}
						if (repaisitem.confirmSelectFaultItem.level == 5) {
							Repairs.Solution = repaisitem.confirmSelectFaultItem.RepairFaultId;
						}
						repaisitem.confirmSelectFaultItem = repaisitem.confirmSelectFaultItem.parentFaultItem;
					}
					if (repaisitem.confirmSelectFaultItem.level == 1) {
						Repairs.FaultClass = repaisitem.confirmSelectFaultItem.RepairFaultId;
					}
					// 是否换件
					if (repaisitem.switchReplacePart)
						Repairs.IsReplace = repaisitem.switchReplacePart;
					// 保内保外
					if (repaisitem.faultPartItem.InOrOffWarranty)
						Repairs.Warranty = repaisitem.faultPartItem.InOrOffWarranty;
					// 客户产品配件行Id
					if (repaisitem.faultPartItem.CustProductPartsGuid)
						Repairs.Assemblybom = repaisitem.faultPartItem.CustProductPartsGuid;
					// 整机配件行Id
					if (repaisitem.faultPartItem.ProductBomGuid)
						Repairs.EnsembleAccessoryStructure = repaisitem.faultPartItem.ProductBomGuid;
					// 故障件ID
					if (repaisitem.faultPartItem.PartsGuid)
						Repairs.FaultProduct = repaisitem.faultPartItem.PartsGuid;
					// 故障件名称
					if (repaisitem.faultPartItem.PartsName)
						Repairs.FaultProdName = repaisitem.faultPartItem.PartsName;
					// 更换件ID
					if (repaisitem.changeFaultPartItem.PartsGuid)
						Repairs.ChangeParts = repaisitem.changeFaultPartItem.PartsGuid;
					// 更换件名称
					if (repaisitem.changeFaultPartItem.PartsName)
						Repairs.ChangePartName = repaisitem.changeFaultPartItem.PartsName;
					// 维修备注
					if (repaisitem.RepairMarks)
						Repairs.RepairMarks = repaisitem.RepairMarks;
					// 保内转保外
					if (repaisitem.IsInWarrantyToOut)
						Repairs.IsInWarrantyToOut = repaisitem.IsInWarrantyToOut;
					// 保内转保外原因代码ID
					if (repaisitem.OutWarrntyToInReasonCode)
						Repairs.InWarrantyToOutReasonCode = repaisitem.OutWarrntyToInReasonCode;
					// 保外转保内
					if (repaisitem.IsOutWarrantyToIn)
						Repairs.IsOutWarrantyToIn = repaisitem.IsOutWarrantyToIn;
					// 保外转保内原因代码ID
					if (repaisitem.OutWarrntyToInReasonCode)
						Repairs.OutWarrntyToInReasonCode = repaisitem.OutWarrntyToInReasonCode;
					// 保内保外备注
					if (repaisitem.WarrantyMarks)
						Repairs.WarrantyMarks = repaisitem.WarrantyMarks;

					RepairData.push(Repairs);
					prodItem.Repairs[repaisindex].confirmSelectFaultItem = prodItem.Repairs[repaisindex].selectFaultItem;
				}
				product.Repairs = RepairData;
				product.WaterAnalysis = waterAnalysis;
				this.woProducts.push(product);
			}
		},

		//构建缓存信息
		GetCacheOrderInfo() {
			//工单信息
			// let cacheOrderData = {};
			// cacheOrderData.woTransInfo = {};
			this.woCacheData.WoProduct = []; //产品信息
			this.woCacheData.FinishType = this.orderDetailData.WoFinishType; //完工类型
			this.woCacheData.Description = this.OrderRremark //备注
			this.woCacheData.RepairType = this.repairTypeList[this.repairTypeIndex].value; //维修方式
			this.woCacheData.IsRepalced = false; //是否换机
			this.woCacheData.ActualReceivedAmount = this.ActualReceiptAmount; //实际收款总金额
			this.woCacheData.CustomerRequiresMaintenanceDate = this.CustomerRequiresMaintenanceDate; //客户服务时间
			for (let index in this.orderDetailData.WoProuduct) {
				let prodItem = this.orderDetailData.WoProuduct[index];
				//水质检测信息
				let waterAnalysis = {
					OriWaterAnalysisId: prodItem.OriWaterAnalysisId,
					OriTDS: prodItem.OriTDS,
					OriTemperature: prodItem.OriTemperature,
					OriHardness: prodItem.OriHardness,
					OriChlorine: prodItem.OriChlorine,
					NewTDS: prodItem.NewTDS,
					NewHardness: prodItem.NewHardness,
					NewChlorine: prodItem.NewChlorine,
					IsWaterAnalysis: prodItem.IsWaterAnalysis,
					ProductSeriesId: prodItem.ProductSeriesId,
					ProductSeriesName: prodItem.ProductSeriesName,
					IsRequired: prodItem.IsRequired,
					WaterAnalysisFieldRequired: prodItem.WaterAnalysisFieldRequired,
					IsShowWaterAnalysisAddBtn: prodItem.isShowWaterAnalysisAddBtn,
				};
				let prodImg; //图片
				if (prodItem.ProductImage) {
					prodImg = prodItem.ProductImage.replace("data:image/jpeg;base64,", "");
				}
				let product = {
					ServiceOrderObject: prodItem.WoObjectId, // 服务工单对象
					Barcode: prodItem.Barcode, // 物流码
					New_Barcode: "", //换机新物流码
					IsSerialValid: prodItem.IsSerialValid, //物流码有效性
					PurchaseDate: prodItem.PurchaseDate, // 购机日期
					Product: prodItem.ProuctId, // 产品
					ProdTypeGroup: prodItem.ProdTypeGroup, //产品类型
					ProductImage: prodImg, //图片
					ProductName: prodItem.ProductName, //产品名称
					ProductNum: prodItem.ProductNum, //产品编号
					Province: "", // 新省/市
					City: "", // 新市/区
					County: "", // 新区/县
					Street: "", // 新街道
					InstalledLocation: prodItem.InstallLocation, // 安装位置
					InstalledLocatuion_New: "", // 新安装位置
					SuitProductItems: "", //套装产品项
					Repairs: prodItem.Repairs, //维修信息
					Maintains: [], //保养信息
					WaterAnalysis: waterAnalysis, //水质检测
				};
				this.woCacheData.WoProduct.push(product);
			}
			return JSON.stringify(this.woCacheData);
		},
		//给工单信息赋值
		AssignOrderInfo(woData) {
			this.OrderRremark = woData.WORemark; //备注
			this.CustomerRequiresMaintenanceDate = woData.CustomerRequiresMaintenanceDate ?
				woData.CustomerRequiresMaintenanceDate : ""; //客户产品日期
			this.ActualReceiptAmount = woData.ActualReceivedAmount ? woData.ActualReceivedAmount : ""; //实际金额
			this.repairTypeIndex = woData.RepairType ? woData.RepairType - 1 : 0; //维修方式
			//console.log("日期信息",this.CustomerRequiresMaintenanceDate,woData.CustomerRequiresMaintenanceDate);
		},
		//判断工单中是否有保外机器
		GetActualReceiptAmountShow(addrepairData){
			for (let index in addrepairData) {
				let item = addrepairData[index];
				if(item.faultPartItem){
					let PartShelfLife = item.faultPartItem.InOrOffWarranty;
					if(PartShelfLife!=2)
					{
						return true;					
					}
				}
			}
			return false;
		},
	}
}
